/*
    Copyright (C) 2019 Zongming Liu <1849059316@qq.com>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "StartScene.h"
#include "GameLevelScene.h"
#include "../Game.h"

StartScene::StartScene()
{
}

StartScene::~StartScene()
{
}

bool StartScene::initUi()
{
    auto cache = GameWorld::getInstance()->getDefultSpriteFrameCache();
    auto game_size = GameWorld::getInstance()->getAppView()->getViewSize();

    //初始化背景
    auto bg_sf = cache->getSpriteFrame(L"start_bg");
    m_background = Sprite::create(bg_sf, this);
    m_background->setPosition(game_size.width / 2, game_size.height / 2);

    //初始化按钮
    auto normal_sf = cache->getSpriteFrame(L"start2");
    auto pushed_sf = cache->getSpriteFrame(L"start1");
    m_butStart = PushButton::create();
    m_butStart->setNormalImage(Scale9Image::createUniquePtr(normal_sf, Rect::Zero));
    m_butStart->setPushedImage(Scale9Image::createUniquePtr(pushed_sf, Rect::Zero));
    m_butStart->resize(Size(500, 170));
    m_butStart->move((game_size.width - 500) / 2, 200);

    //设置点击按钮的回掉
    m_butStart->setClickedListener([this](EventMouse *e)
                                   {
                                       Game::getInstance()->playAudio(Game::AudioType::BUTTON_AUDIO);

                                       GameWorld::getInstance()->getScheduler()->addSchedulerTaskDelay([]()
                                                                                                       { Game::getInstance()->nextGameLevelScene(); },
                                                                                                       "{ACEA285E-01EF-417B-ABAC-B7005F9A8B0F}", 1000); });

    return true;
}

void StartScene::enterScene()
{
    if (!this->initUi())
    {
        return;
    }
    return;
}

void StartScene::quitScene()
{
}
